package com.ruoyi.asset.extermination.controller;


import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.asset.extermination.domain.bo.DisinfectionBo;
import com.ruoyi.asset.extermination.domain.bo.DisinfectionStatisticsBo;
import com.ruoyi.asset.extermination.domain.vo.DisinfectionVo;
import com.ruoyi.asset.extermination.domain.vo.ExterminationCommunityCountVo;
import com.ruoyi.asset.extermination.domain.vo.ExterminationWorkStatisticsVo;
import com.ruoyi.asset.extermination.service.IDisinfectionService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 四害消杀管养
 *
 * @author 12276
 */
@Validated
@RequiredArgsConstructor
@RestController
    @RequestMapping("/asset/extermination")
public class DisinfectionController extends BaseController {

    private final IDisinfectionService exterminationService;

    /**
     * 获取四害消杀管养-管理范围导入模板
     */
    @SaIgnore()
    @Log(title = "四害消杀管养范围导入", businessType = BusinessType.IMPORT)
    @RepeatSubmit()
    @PostMapping(value = "/importData")
    public R<List<String>> importData(@RequestParam(name = "excelUrl") String excelUrl) {
        List<String> list = this.exterminationService.importExcel(excelUrl);

        if (list == null) {
            return R.fail();
        } else {
            return R.ok(list);
        }
    }

    /**
     * 获取四害消杀管养-管理范围导入模板
     */
    @SaIgnore()
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) {
        ExcelUtil.exportExcel(new ArrayList<>(), "四害消杀管养管理范围导入模板", DisinfectionVo.class, response);
    }

    /**
     * 删除四害消杀管养范围
     */
    @SaIgnore()
    @DeleteMapping("/deleteExtermination/{ids}")
    public R<Void> deleteExtermination(@NotEmpty(message = "主键不能为空")
                                          @PathVariable Set<Long> ids) {
        int count = this.exterminationService.deleteExtermination(ids);

        return toAjax(count >= 0 ? 1 : count);
    }

    /**
     * 查询四害消杀管养范围
     */
    @SaIgnore()
    @GetMapping("/queryExtermination")
    public TableDataInfo<DisinfectionVo> queryExtermination (DisinfectionBo searchBo, PageQuery pageQuery) {
        return this.exterminationService.queryExtermination(searchBo, pageQuery);
    }

    /**
     * 导出四害消杀管养范围
     */
    @SaIgnore()
    @Log(title = "四害消杀管养范围导出", businessType = BusinessType.EXPORT)
    @PostMapping("/exportExtermination")
    public void exportExtermination(DisinfectionBo searchBo, HttpServletResponse response) {
        List<DisinfectionVo> list = this.exterminationService.exportExtermination(searchBo);

        ExcelUtil.exportExcel(list, "四害消杀管养范围", DisinfectionVo.class, response);
    }

    @SaIgnore()
    @GetMapping("/disinfectionCount")
    public R<DisinfectionStatisticsBo> disinfectionCount() {
        DisinfectionStatisticsBo disinfectionCount = exterminationService.getDisinfectionCount();
        return R.ok(disinfectionCount);
    }

    @SaIgnore()
    @GetMapping("/disinfectionCommunityCount")
    public R<Map> disinfectionCommunityCount() {
        Map map = exterminationService.getDisinfectionCommunityCount();
        return R.ok(map);
    }

    /**
     * 查询智慧大屏四害消杀玉塘街道全社区
     * @param date
     * @return
     */
    @SaIgnore()
    @GetMapping("/exterminationCommunity")
    public R<List<ExterminationCommunityCountVo>>  exterminationCommunity(String date) {
        date = "2024-03-13";
        List<ExterminationCommunityCountVo> exterminationCountByCommunity = exterminationService.getExterminationCountByCommunity(date);
        return R.ok(exterminationCountByCommunity);
    }

    /**
     * 查询智慧大屏四害消杀今日作业统计与百分比
     * @param date
     * @return
     */
    @SaIgnore()
    @GetMapping("/exterminationWorkByDate")
    public R<ExterminationWorkStatisticsVo> exterminationWorkByDate(String date) {
        date = "2024-03-13";
        ExterminationWorkStatisticsVo exterminationWorkStatisticsVo = exterminationService.getExterminationWorkByDate(date);
        return R.ok(exterminationWorkStatisticsVo);
    }

}
